

*********************************************************
*
*                  Rwanda 2012 Census Summary Stats Do                    
*
*********************************************************
use "$main/01_data/02_clean/RPHC-2012-DATA-V2.DTA", clear

******Getting Ready for the analysis!***********

* Generate a district identifier from Questions L01 and L02 
gen district=0
replace district = (L01*10 + L02) // Please refer to the code book for district names

* Now generate a sample district identifier 
gen sampledistrict =.
foreach i in 31 34 35 41 42 43 45 53 54 56 57 {
replace sampledistrict =`i' if district == `i'
}


*********************************************************
*
*                  Summary Stats                        
*
*********************************************************


*************************HH Size************************
sum HHSize // Average HHsize - Nationwide
*Average HHsize - sample / non-sample districts
sum HHSize if sampledistrict !=. 
sum HHSize if sampledistrict ==.
*Average HHsize - each sample disctrict
foreach i in 31 34 35 41 42 43 45 53 54 56 57 {
sum HHSize if sampledistrict ==`i'
}
tab HHSize sampledistrict, column // tabulate HHsizes of each sample district

************************* Average # of Childern Born *****************
replace P33M=. if P33M ==98 | P33M==99
replace P33F=. if P33F ==98 | P33F==99
gen childernborn = P33M+P33F

sum childernborn // nationwide 
sum childernborn if sampledistrict !=. // sample districts 
sum childernborn if sampledistrict ==. // non sample districts 

*Breaking down by each sample district
foreach i in 31 34 35 41 42 43 45 53 54 56 57 {
sum childernborn if sampledistrict ==`i'
}

******************Rural / Urban **************************
tab RL07 // nationwide
*Rural/Urban by Sample Disctricts/ Non-Sample Disctricts
tab RL07 if sampledistrict !=. // rural-urban - Sample Disctricts
tab RL07 if sampledistrict ==. // rural-urban - Non-Sample Disctricts
** Rural / Urban - each sample disctrict
tab RL07 sampledistrict

**************************% in Agriculture****************
gen agriculture = (P25>6000 & P25<7000) //according to the code book, code starting with 6 means "SKILLED AGRICULTURE, FORESTRY AND FISHERY WORKERS"
replace agriculture =. if P25==9998 | P25==9999 // replace Not Applicable and Missing with .
tab agriculture if P05>=15 & P05<65 //% Labor Force Working in Agriculture Sector - Nationwide
tab agriculture if sampledistrict !=. & P05>=15 & P05<65 // % Labor Force Working in Agriculture Sector - Sample Disctricts
tab agriculture if sampledistrict ==. & P05>=15 & P05<65 // % Labor Force Working in Agriculture Sector - Non Smple Disctricts
tab agriculture sampledistrict if P05>=15 & P05<65 // percentage of agricultural workers in each districts - all labor force 

*************************************************************
****************** Eudcation ********************************
*************************************************************

*Age group defined by UN: adolescents: 15-19 young adults: 20-24 labor force: 15-64

************Education Level Attained********************

***Education - Nationwide
*Education - labor force 
tab P18A if P05>=15 & P05<65
*Education - adolescents
tab P18A if P05>=15 & P05<20
*Education - young adults
tab P18A if P05>=20 & P05<25

***Education - Sampling Districts
*Education - labor force 
tab P18A if P05>=15 & P05<65 & sampledistrict !=.
*Education - adolescents
tab P18A if P05>=15 & P05<20 & sampledistrict !=.
*Education - young adults
tab P18A if P05>=20 & P05<25 & sampledistrict !=.

***Education - Non-Sampling Districts
*Education - labor force 
tab P18A if P05>=15 & P05<65 & sampledistrict ==.
*Education - adolescents
tab P18A if P05>=15 & P05<20 & sampledistrict ==.
*Education - young adults
tab P18A if P05>=20 & P05<25 & sampledistrict ==.

*** Education - Sample Districts - Seperately 
*Education - labor force 
tab P18A sampledistrict if P05>=15 & P05<65
*Education - adolescents
tab P18A sampledistrict if P05>=15 & P05<20
*Education - young adults
tab P18A sampledistrict if P05>=20 & P05<25 

************Literacy********************

* Generate a Literacy dummy
gen literacy =( P16!=0)
replace literacy =. if P16==99 | P16==999

**Nationwide
*Literacy - labor force 
tab literacy if P05>=15 & P05<65
*Literacy - adolescents
tab literacy if P05>=15 & P05<20
*Literacy - young adults
tab literacy if P05>=20 & P05<25

**Sample Districts
*Literacy - labor force 
tab literacy if P05>=15 & P05<65 & sampledistrict !=.
*Literacy - adolescents
tab literacy if P05>=15 & P05<20 & sampledistrict !=.
*Literacy - young adults
tab literacy if P05>=20 & P05<25 & sampledistrict !=.

**Non Sample Districts
*Literacy - labor force 
tab literacy if P05>=15 & P05<65 & sampledistrict ==.
*Literacy - adolescents
tab literacy if P05>=15 & P05<20 & sampledistrict ==.
*Literacy - young adults
tab literacy if P05>=20 & P05<25 & sampledistrict ==.

**Each Sample District
*Literacy - labor force 
tab literacy sampledistrict if P05>=15 & P05<65
*Literacy - adolescents
tab literacy sampledistrict if P05>=15 & P05<20
*Literacy - young adults
tab literacy sampledistrict if P05>=20 & P05<25 

************************** School Enrollment ************************************

* Ages: 3-18: official age range to attend school (from pre-school to secondary level)
tab P17 if P05>=13 & P05<=18 // Nationwide 
tab P17 if P05>=13 & P05<=18 & sampledistrict !=. // Sample Districts
tab P17 if P05>=13 & P05<=18 & sampledistrict ==. // Non Sample Districts
tab P17 sampledistrict if P05>=13 & P05<=18 // Each Sample District

* Ages: 3-6: pre-school program
tab P17 if P05>=3 & P05<=6 // Nationwide 
tab P17 if P05>=3 & P05<=6 & sampledistrict !=. // Sample Districts
tab P17 if P05>=3 & P05<=6 & sampledistrict ==. // Non Sample Districts
tab P17 sampledistrict if P05>=3 & P05<=6 // Each Sample District

* Ages: 7-12: official age for primary school
tab P17 if P05>=7 & P05<=12 // Nationwide 
tab P17 if P05>=7 & P05<=12 & sampledistrict !=. // Sample Districts
tab P17 if P05>=7 & P05<=12 & sampledistrict ==. // Non Sample Districts
tab P17 sampledistrict if P05>=7 & P05<=12 // Each Sample District

* Ages 13-18: eligible to attend secondary school
tab P17 if P05>=13 & P05<=18 // Nationwide 
tab P17 if P05>=13 & P05<=18 & sampledistrict !=. // Sample Districts
tab P17 if P05>=13 & P05<=18 & sampledistrict ==. // Non Sample Districts
tab P17 sampledistrict if P05>=13 & P05<=18 // Each Sample District


*****Employment - Nationwide (Emplpyment Status is not applicable for childern under 5)**********

*Employment - labor force 
tab P28 if P05>=15 & P05<65
*Employment - young adults
tab P28 if P05>=20 & P05<25

***Employment - Sampling Districts
*Employment - labor force 
tab P28 if P05>=15 & P05<65 & sampledistrict !=.
*Employment - young adults
tab P28 if P05>=20 & P05<25 & sampledistrict !=.

***Employment - Non-Sampling Districts
*Employment - labor force 
tab P28 if P05>=15 & P05<65 & sampledistrict ==.
*Employment - young adults
tab P28 if P05>=20 & P05<25 & sampledistrict ==.

*** Employment - Sample Districts - Seperately 
*Employment - labor force 
tab P28 sampledistrict if P05>=15 & P05<65
*Employment - young adults
tab P28 sampledistrict if P05>=20 & P05<25 

********************* Employment 2 *************************
*% employed, among those in labor force (variable P20: share of "yes" working divided by "yes" + "no" group)
replace P20 =. if P20== 9 | P20==99
tab P20 if P05>=15 & P05<65 //nationwide
tab P20 if P05>=15 & P05<65 & sampledistrict !=. // sample districts
tab P20 if P05>=20 & P05<25 & sampledistrict ==. // non sample districts
tab P26 if P05>=15 & P05<65 & P20==1

******************* Employment 3 ******************************
*% self-employed or family worker among employed (variable P26: those in self-employed or family worker category, conditional on P20=yes)
tab P26 if P05>=15 & P05<65 & P20==1 // Nationwide
tab P26 if P05>=15 & P05<65 & P20==1 & sampledistrict !=. // sample districts
tab P26 if P05>=15 & P05<65 & P20==1 & sampledistrict ==. // non sample districts
tab P26 sampledistrict if P05>=15 & P05<65 & P20==1


*******************************************************************
************************ HH Assets ********************************
*******************************************************************

**************************Internet Access******************
gen internet = (H26==1)
replace internet =. if H26==9

tab internet // nationwide 
tab internet if sampledistrict !=. // sample districts
tab internet if sampledistrict ==. // non-sample districts
tab internet sampledistrict, column

**********************Cell Phone***************************
gen cellphone = (H20!=0)
replace cellphone =. if H20==99

tab cellphone // nationwide 
tab cellphone if sampledistrict !=. // sample districts
tab cellphone if sampledistrict ==. // non-sample districts
tab cellphone sampledistrict, column

**********************Computer***************************
gen computer = (H22!=0)

tab computer // nationwide 
tab computer if sampledistrict !=. // sample districts
tab computer if sampledistrict ==. // non-sample districts
tab computer sampledistrict, column

